﻿Imports DAL
Public Class ColetaBLL

    Dim ObjDAL As ColetaDAL


    Public Function RetItens(ColCodigo As Integer) As DataTable
        Try
            ObjDAL = New ColetaDAL
            Return ObjDAL.RetItens(ColCodigo)
        Catch ex As Exception
            Throw
        End Try
    End Function

    Public Function ValidaItens(ColCodigo As Integer, EleCodigo As Integer) As Boolean
        Try
            Dim Tab As DataTable
            ObjDAL = New ColetaDAL
            Tab = ObjDAL.validaItens(ColCodigo, EleCodigo)
            If (Tab.Rows.Count > 0) Then : Throw New Exception("Eletrônico já cadastrado")
            End If
            Return True
        Catch ex As Exception
            Throw
        End Try
    End Function

    Public Function InsereColeta(ColCodigo As Integer, Data As DateTime, PesCodigo As Integer, nome As String) As Integer
        Try
            ObjDAL = New ColetaDAL
            Return ObjDAL.InsereColeta(ColCodigo, Data, PesCodigo, nome)
        Catch ex As Exception
            Throw
        End Try
    End Function

    Public Sub InsereItens(ColCodigo As Integer, EleCodigo As Integer, CelQtde As Integer, Unidade As Integer)
        Try
            ObjDAL = New ColetaDAL
            If (ValidaItens(ColCodigo, EleCodigo)) Then
                ObjDAL.InsereItens(ColCodigo, EleCodigo, CelQtde, Unidade)
            End If
        Catch ex As Exception
            Throw
        End Try
    End Sub

    Public Sub AlteraItens(ColCodigo As Integer, EleCodigo As Integer, CelQtde As Integer, Unidade As Integer)
        Try
            ObjDAL = New ColetaDAL
            Dim ObjEletronico = New EletronicosBLL(EleCodigo)
            ObjDAL.AlteraItens(ColCodigo, EleCodigo, CelQtde, Unidade)
        Catch ex As Exception
            Throw
        End Try
    End Sub

    Public Sub ExcluirItens(ColCodigo As Integer, EleCodigo As Integer)
        Try
            ObjDAL = New ColetaDAL
            ObjDAL.ExcluiItens(ColCodigo, EleCodigo)
        Catch ex As Exception
            Throw
        End Try
    End Sub

#Region "Buscar"
    Function buscar(ByVal descricao As String, tipo As Integer) As DataTable
        Dim ret As DataTable
        Try
            ObjDAL = New ColetaDAL
            ret = ObjDAL.buscar(descricao, tipo)
        Catch ex As Exception
            Throw ex
        Finally
            ObjDAL = Nothing
        End Try
        Return ret
    End Function
#End Region
End Class
